package com.scuec.groupfive.mapper;

import com.scuec.groupfive.entity.UserInfo;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserproMapper {

    @Select("select * from user_info where user_id=#{id}")
    public UserInfo getUserInfoById(Integer id);
    // 新增：根据邮箱查询用户
    @Select("SELECT * FROM users WHERE email = #{email}")
    UserInfo getUserByEmail(String email);

    @Update("update users set username=#{username}, email=#{email}, phone=#{phone}, " +
            "real_name=#{realName}, gender=#{gender}, avatar=#{avatar}, school=#{school}, " +
            "target_school=#{targetSchool}, exam_year=#{examYear}, status=#{status}, " +
            "updated_at=NOW() where user_id=#{userId}")
    public Integer updateUserInfo(UserInfo userInfo);

    @Update("update users set email=#{email}, phone=#{phone}, real_name=#{realName}, " +
            "gender=#{gender}, avatar=#{avatar}, school=#{school}, target_school=#{targetSchool}, " +
            "exam_year=#{examYear}, updated_at=NOW() where user_id=#{userId}")
    public Integer updateUserProfile(UserInfo userInfo);

    @Update("update users set password=#{password}, updated_at=NOW() where user_id=#{userId}")
    public Integer updateUserPassword(UserInfo userInfo);

    @Update("update users set last_login_time=NOW() where user_id=#{userId}")
    public Integer updateLastLoginTime(Integer userId);

    @Delete("DELETE FROM users WHERE user_id = #{userId}")
    public Integer deleteUserById(Integer userId);
}